using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Lifter.Gui.Monitor.Controls.Buttons
{
    public class ButtonInterlock : BaseControl
    {
        public enum INTERLOCK_LAMP_POSITION
        {
            TOP = 1,
            LEFT,
            RIGHT,
            BOTTOM
        }
        private ButtonXP button = null;
        private Font captionFont = new Font("Arial", 9f);
        private string caption = "Button";
        private bool isInterlockLampVisible = false;
        private Color interlockLampColor = Color.Red;
        private ButtonInterlock.INTERLOCK_LAMP_POSITION interlockLampPosition = ButtonInterlock.INTERLOCK_LAMP_POSITION.LEFT;
        private IContainer components = null;
        public Font CaptionFont
        {
            get
            {
                return this.captionFont;
            }
            set
            {
                this.captionFont = value;
                base.Invalidate();
            }
        }
        public string Caption
        {
            get
            {
                return this.caption;
            }
            set
            {
                this.caption = value;
                base.Invalidate();
            }
        }
        public bool IsInterlockLampVisible
        {
            get
            {
                return this.isInterlockLampVisible;
            }
            set
            {
                this.isInterlockLampVisible = value;
                base.Invalidate();
            }
        }
        public Color InterlockLampColor
        {
            get
            {
                return this.interlockLampColor;
            }
            set
            {
                this.interlockLampColor = value;
                base.Invalidate();
            }
        }
        public ButtonInterlock.INTERLOCK_LAMP_POSITION InterlockLampPosition
        {
            get
            {
                return this.interlockLampPosition;
            }
            set
            {
                this.interlockLampPosition = value;
                base.Invalidate();
            }
        }
        public ButtonInterlock()
        {
            this.InitializeComponent();
            this.button = new ButtonXP();
            this.button.BackColor = Color.Transparent;
            base.Controls.Add(this.button);
            this.button.Click += new EventHandler(this.ButtonClick);
        }
        private void ButtonClick(object sender, EventArgs e)
        {
            this.OnClick(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            Point location = new Point(0, 0);
            Size size = new Size(0, 0);
            Point location2 = new Point(0, 0);
            Size size2 = new Size(0, 0);
            SolidBrush drawColor = new SolidBrush(this.interlockLampColor);
            if (this.InterlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.RIGHT || this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.BOTTOM)
            {
                location.X = 0;
                location.Y = 0;
            }
            else
            {
                if (this.InterlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.LEFT)
                {
                    location.X = 8;
                    location.Y = 0;
                }
                else
                {
                    if (this.InterlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.TOP)
                    {
                        location.X = 0;
                        location.Y = 8;
                    }
                }
            }
            this.button.Location = location;
            if (this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.LEFT || this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.RIGHT)
            {
                size = new Size(base.Width - 8, base.Height);
            }
            else
            {
                size = new Size(base.Width, base.Height - 8);
            }
            this.button.Size = size;
            this.button.Font = this.captionFont;
            this.button.Text = this.caption;
            if (this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.LEFT || this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.RIGHT)
            {
                size2 = new Size(10, base.Height - 16);
            }
            else
            {
                size2 = new Size(base.Width - 16, 10);
            }
            if (this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.RIGHT)
            {
                location2 = new Point(base.Width - 11, 8);
            }
            else
            {
                if (this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.LEFT)
                {
                    location2 = new Point(0, 8);
                }
                else
                {
                    if (this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.TOP)
                    {
                        location2 = new Point(8, 0);
                    }
                    else
                    {
                        if (this.interlockLampPosition == ButtonInterlock.INTERLOCK_LAMP_POSITION.BOTTOM)
                        {
                            location2 = new Point(8, base.Height - 11);
                        }
                    }
                }
            }
            if (this.isInterlockLampVisible)
            {
                Rectangle rect = new Rectangle(location2, size2);
                base.DrawRoundRect(graphics, rect, 2, drawColor, Brushes.Black, 1);
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        {
            this.components = new Container();
        }
    }
}
